import store from '@/store'

/**
 * 获取对应桶state值
 * @param {String} name 存储桶名称
 * @param {String} key key值
 */
export function storeGetState(name:string, key:string) {
  // eslint-disable-next-line no-prototype-builtins
  if (store.state.hasOwnProperty(name) && store.state[ name ].hasOwnProperty(key)) {
    return store.state[ name ][ key ]
  }
  return ''
}

/**
 * 获取对应桶getter值
 * @param {String} name getters名
 */
export function storeGetter(name:string) {
  // eslint-disable-next-line no-prototype-builtins
  if (store.getters.hasOwnProperty(name)) {
    return store.getters[ name ]
  }
  return ''
}

/**
 * commit方法
 * @param {String} name commit方法名！！
 */
export function storeCommit(name:string, params?:any) {
  store.commit(name, params)
}

/**
 * actions方法
 * @param {String} name action方法名!!
 */
export function storeAction(name:string, params?:any) {
  return store.dispatch(name, params)
}
